﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.workers {
    import flash.utils.*;

    public class WorkerManager {

        public static const FEATURE_FACTORIES:String = "factories";
        public static const FEATURE_COPS_N_BANDITS:String = "copsNBandits";
        public static const FEATURE_TRAINS:String = "trains";

        private var m_workerMap:Dictionary;
        private var m_featureName:String;

        public function WorkerManager(_arg1:String=null){
            this.m_workerMap = new Dictionary();
            this.m_featureName = _arg1;
        }
        public function cleanUp():void{
            var _local1:String;
            var _local2:Workers;
            if (this.m_workerMap){
                for (_local1 in this.m_workerMap) {
                    _local2 = this.m_workerMap[_local1];
                    if (_local2){
                        _local2.cleanUp();
                    };
                    delete this.m_workerMap[_local1];
                };
            };
        }
        public function loadObject(_arg1:Object):void{
            var _local2:String;
            var _local3:Object;
            var _local4:Workers;
            if (_arg1){
                for (_local2 in _arg1) {
                    _local3 = _arg1[_local2];
                    _local4 = this.createWorkers(this.m_featureName);
                    _local4.loadObject(_local3);
                    this.m_workerMap[_local2] = _local4;
                };
            };
        }
        public function preserveAndLoadObject(_arg1:Object):void{
            var _local2:String;
            var _local3:Object;
            var _local4:Workers;
            if (_arg1){
                for (_local2 in _arg1) {
                    if (this.m_workerMap[_local2]){
                        (this.m_workerMap[_local2] as Workers).preserveAndLoadObject(_arg1[_local2]);
                    } else {
                        _local3 = _arg1[_local2];
                        _local4 = this.createWorkers(this.m_featureName);
                        _local4.loadObject(_local3);
                        this.m_workerMap[_local2] = _local4;
                    };
                };
            };
        }
        public function getWorkers(_arg1:String):Workers{
            var _local2:Workers;
            if (this.m_workerMap.hasOwnProperty(_arg1)){
                _local2 = this.m_workerMap[_arg1];
            };
            return (_local2);
        }
        public function addWorkers(_arg1:String, _arg2:Workers):Boolean{
            if (this.m_workerMap.hasOwnProperty(_arg1)){
                return (false);
            };
            this.m_workerMap[_arg1] = _arg2;
            return (true);
        }
        public function addAndGetWorkers(_arg1:String):Workers{
            var _local2:Workers = this.getWorkers(_arg1);
            if (!_local2){
                _local2 = this.createWorkers(this.m_featureName);
                this.addWorkers(_arg1, _local2);
            };
            return (_local2);
        }
        public function updateWorkers(_arg1:String, _arg2:Workers):Boolean{
            if (!this.m_workerMap.hasOwnProperty(_arg1)){
                return (false);
            };
            this.m_workerMap[_arg1] = _arg2;
            return (true);
        }
        public function hasWorkers(_arg1:String):Boolean{
            var _local2:Workers = this.getWorkers(_arg1);
            return (((_local2) && ((_local2.getWorkerCount() > 0))));
        }
        public function resetWorkers(_arg1:String, _arg2:Boolean=true):Workers{
            var _local3:Workers;
            if (this.m_workerMap.hasOwnProperty(_arg1)){
                _local3 = this.m_workerMap[_arg1];
                this.m_workerMap[_arg1].cleanUp(_arg2);
            };
            return (_local3);
        }
        public function clearWorkers(_arg1:String):Workers{
            var _local2:Workers;
            if (this.m_workerMap.hasOwnProperty(_arg1)){
                _local2 = this.m_workerMap[_arg1];
                delete this.m_workerMap[_arg1];
            };
            return (_local2);
        }
        protected function createWorkers(_arg1:String):Workers{
            var _local2:Workers;
            switch (_arg1){
                case FEATURE_FACTORIES:
                    _local2 = new FactoryWorkers();
                    break;
                case "copsNBandits":
                    _local2 = new CopsNBanditsWorkers();
                    break;
                case FEATURE_TRAINS:
                    _local2 = new TrainWorkers();
                    break;
                default:
                    _local2 = new Workers();
            };
            return (_local2);
        }

    }
}//package Modules.workers 
